import {Route, Redirect } from 'react-router-dom'
import consumerContext from '../../context/consumerContext'
import { useContext } from 'react'

function PrivateRoute (props) {
  const { state } = useContext(consumerContext)
  return state.token ? <Route exact path={props.path} component={props.component} />
  : <Redirect from="/" to="login" />
}
export default PrivateRoute